package com.customDialog;


import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.customDialog.R;

public class CustomDialogTestActivity extends Activity {
	
	static final int CUSTOM_DIALOG_ID = 0;
	 
		TextView customDialog_TextView;
		EditText customDialog_EditText;
		Button customDialog_Update, customDialog_Dismiss;
	;
	 
	   /** Called when the activity is first created. */
	   @Override
	   public void onCreate(Bundle savedInstanceState) {
	       super.onCreate(savedInstanceState);
	       setContentView(R.layout.main);
	       
	       Button buttonStartDialog = (Button)findViewById(R.id.startdialog);
	       buttonStartDialog.setOnClickListener(new Button.OnClickListener(){
	 
					  @Override
					  public void onClick(View arg0) {
					   // TODO Auto-generated method stub
					   showDialog(CUSTOM_DIALOG_ID);
					  }
					       });
	   }
	   
	   private Button.OnClickListener customDialog_UpdateOnClickListener
	   = new Button.OnClickListener(){
	 
					 @Override
					 public void onClick(View arg0) {
					  // TODO Auto-generated method stub
					  customDialog_TextView.setText(customDialog_EditText.getText().toString());
					 }
					    
		};
	   
	   private Button.OnClickListener customDialog_DismissOnClickListener
	   = new Button.OnClickListener(){
	 
				 @Override
				 public void onClick(View arg0) {
				  // TODO Auto-generated method stub
				  dismissDialog(CUSTOM_DIALOG_ID);
				 }
				    
		 };
	   
	@Override
	protected Dialog onCreateDialog(int id) {
	 // TODO Auto-generated method stub
	 Dialog dialog = null;;
	    switch(id) {
	    case CUSTOM_DIALOG_ID:
	     dialog = new Dialog(CustomDialogTestActivity.this);
	 
	     dialog.setContentView(R.layout.customlayout);
	     dialog.setTitle("Custom Dialog");
	     
	     customDialog_EditText = (EditText)dialog.findViewById(R.id.dialogedittext);
	     customDialog_TextView = (TextView)dialog.findViewById(R.id.dialogtextview);
	     customDialog_Update = (Button)dialog.findViewById(R.id.dialogupdate);
	     customDialog_Dismiss = (Button)dialog.findViewById(R.id.dialogdismiss);
	     
	     customDialog_Update.setOnClickListener(customDialog_UpdateOnClickListener);
	     customDialog_Dismiss.setOnClickListener(customDialog_DismissOnClickListener);
	     
	        break;
	    }
	    return dialog;
	}  
}